/*
 * grabcut.cpp
 *
 *  Created on: Aug 19, 2013
 *      Author: root
 */
#if 0

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( )
{
 // Open another image
    Mat image;
    image= cv::imread("G.png");

    // define bounding rectangle
    //cv::Rect rectangle(600,105,110,295); //A
    //cv::Rect rectangle(410,78,60,108); //B
    //cv::Rect rectangle(490,310,110,82); //C (feet only)
    //cv::Rect rectangle(386,120,32,39); //D
    //cv::Rect rectangle(380,130,47,57); //E
    //cv::Rect rectangle(390,121,50,72); //F
    cv::Rect rectangle(424,128,48,67); //G

    cv::Mat result; // segmentation result (4 possible values)
    cv::Mat bgModel,fgModel; // the models (internally used)

    // GrabCut segmentation
    cv::grabCut(image,    // input image
                    result,   // segmentation result
                            rectangle,// rectangle containing foreground
                            bgModel,fgModel, // models
                            1,        // number of iterations
                            cv::GC_INIT_WITH_RECT); // use rectangle
    cout << "Done!" <<endl;
    // Get the pixels marked as likely foreground
    cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
    // Generate output image
    cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
    image.copyTo(foreground,result); // bg pixels not copied

    // draw rectangle on original image
    cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
    cv::namedWindow("Image");
    cv::imshow("Image",image);

    // display result
    cv::namedWindow("Segmented Image");
    cv::imshow("Segmented Image",foreground);


    waitKey();
    return 0;

}

#endif
